<?php

namespace app\api\controller\qsy;

use app\admin\model\qsy\Agreement;
use app\admin\model\qsy\Banner;
use app\admin\model\qsy\Other;
use app\admin\model\qsy\Story;
use app\common\controller\Api;
use app\common\helpers\ImageUtil;
use app\common\model\Config;

/**
 * 丘山阅
 */
class Qsy extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    //轮播列表
    public function bannerList()
    {
        $list = Banner::field('img')->where('status','1')->order('create_time desc')->limit(6)->select();
        if($list){
            foreach ($list as $v){
                $v['img'] = ImageUtil::handle($v['img']);
            }
        }
        $this->success('获取成功', $list);
    }

    //故事集列表
    public function storyList()
    {
        $page = $this->request->param('page',1);//页码
        $pageSize = $this->request->param('pageSize',10);//每页展示数量
        $type = $this->request->param('type');
        $where=[
            'status'=>'1'
        ];
        if($type){
            $where['type'] = $type;
        }
        $model = Story::field('id,title,cover_img,create_time')
            ->where($where)
            ->order('create_time desc')
            ->paginate($pageSize, '', ['page' => $page, 'list_rows' => $pageSize]);
        $total= $model->total();
        $list =  $model->items();
        if($list){
            foreach ($list as $v){
                $v['cover_img'] = ImageUtil::handle($v['cover_img']);
            }
        }
        $result = array("total" =>$total , "list" => $list);
        $this->success("获取成功",$result);;
    }

    //故事集详情
    public function storyDetails()
    {
        $id = $this->request->param('id');
        $info =Story::where('id',$id)->find();
        if(!$info){
            $this->success("获取失败");;
        }
        $info['labelArr'] = explode(',',$info['label']);
        $info['cover_img'] = ImageUtil::handle($info['cover_img']);
        $info['video_url'] = ImageUtil::handle($info['video_url']);
        $this->success("获取成功",$info);;
    }

    //项目介绍、合作招商
    public function introductionCooperation()
    {
        $introduction = Config::where('group','introduction')->select();
        $introduction = array_column($introduction,'value','name');
        $cooperation = Config::where('group','cooperation')->select();
        $cooperation = array_column($cooperation,'value','name');
        if(isset($cooperation['img']))   $cooperation['img'] =  ImageUtil::handle($cooperation['img']);
        $this->success("获取成功",['introduction'=>$introduction,'cooperation'=>$cooperation]);;
    }


    //丘山阅-四个图片加文字
    public function otherList()
    {
        $list = Other::field('type,name,img')->order('id')->select();
        if($list){
            foreach ($list as $v){
                $v['img'] = ImageUtil::handle($v['img']);
            }
        }
        $this->success('获取成功', $list);
    }


    //协议列表
    public function agreementList()
    {
        $list = Agreement::all();
        $this->success('获取成功', $list);
    }

    //客服中心
    public function customerService(){

        $kf = Config::where('group','kf')->select();
        $this->success("获取成功",array_column($kf,'value','name'));;
    }
}
